﻿
(function (window) {
    function DiggerObj(id) {
        this.initialize(id);
    }

    var p = DiggerObj.prototype = new createjs.Container();
    // public properties:
    p.diggerId = -1;
    p.digger = null;
    
    p.Container_initialize = p.initialize;
    p.initialize = function (id) {
        
        this.Container_initialize();

        this.containerConten = new createjs.Container();
        this.diggerId = id;
        this.digger = new createjs.Bitmap(preload.getResult('g3'));
        this.regX = 29.5;
        this.regY = 28.5;
        this.x = 29.5;
        this.y = 28.5;
        this.addChild(this.digger);
    };

    p.onEat = function(type,money) {
        this.removeChild(this.digger);
        var dig = new createjs.Bitmap(preload.getResult('g4'));
        var contanerD = new createjs.Container();
        contanerD.alpha = 0;
        
       
        switch (type) {
            case 3:
                var bm1 = new createjs.Bitmap(preload.getResult('g6'));
                var txtMoney1 = new createjs.Text(PortalCommon.formatMoney1000(money), "bold 26px Comic Sans", "#FFFFFF");
                var b = txtMoney1.getBounds();
                txtMoney1.x = (59 - b.width) / 2;
                txtMoney1.y = (57 - b.height) / 2-10;
                contanerD.addChild(bm1, txtMoney1);
                
                break;
            case 2:
                var bm2 = new createjs.Bitmap(preload.getResult('g7'));
                var txtMoney2 = new createjs.Text(PortalCommon.formatMoney1000(money), "bold 26px Comic Sans", "#FFFFFF");
                var b2 = txtMoney2.getBounds();
                txtMoney2.x = (59 - b2.width) / 2;
                txtMoney2.y = (57 - b2.height) / 2 - 10;
                contanerD.addChild(bm2, txtMoney2);
                break;
                
            case 1:
                var bm3 = new createjs.Bitmap(preload.getResult('g8'));
                contanerD.addChild(bm3);
                break;
        }

        createjs.Tween.get(contanerD, { loop: false }).to({ alpha: 1 }, 1000);

        this.addChild(dig, contanerD);

    };

    window.DiggerObj = DiggerObj;

}(window));

